package com.lht.testDemo.four_reference;

import java.lang.ref.WeakReference;

/**
 * @author Eric
 * @version 1.0
 * @date 2019-10-22
 */
public class Weak {

    public static void main(String[] args) throws InterruptedException {
        String value = "yc";
        WeakReference<String>  ref = new WeakReference<>(value);

        System.gc();
        Thread.sleep(1000);
        System.out.println(ref.get());
        //去掉强引用

        value = null;
        System.gc();
        Thread.sleep(2000);
        System.gc();
        Thread.sleep(2000);
        Thread.sleep(2000);
        System.gc();
        Thread.sleep(2000);
        Thread.sleep(2000);
        System.gc();
        Thread.sleep(2000);
        System.out.println(ref.get());

    }
}
